package com.zhanghe.study.spring4.annotation.config.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * 实现自定义的condition
 * @author zh
 * @date 2021/2/21 12:30
 */
public class MyCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Environment environment = context.getEnvironment();
        String profile = environment.getProperty("profile");
        if(profile != null && "test".equals(profile)){
            return true;
        }
        return false;
    }
}
